<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Users</title>
        <!--<link rel="stylesheet" href="Resources/jquery-ui-1.11.2.custom/jquery-ui.css">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap.css.map">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap-theme.css">
        <link rel="stylesheet" href="Resources/bootstrap/css/bootstrap-theme.css.map">
        <link rel="stylesheet" href="Resources/style/general.css">
        <script src="Resources/js/jquery-1.11.1.js"></script>
        <script type="text/javascript" src="Resources/jquery-ui-1.11.2.custom/jquery-ui.js"></script>
        <script type="text/javascript" src="Resources/bootstrap/js/bootstrap.js"></script>
        <link rel="stylesheet" href="Resources/style/general.css">
        <script src="Resources/js/sha3.js"></script>-->
    </head>
    <body>
        <?php include_once '../PlantillasUI/_MainLayout.php'; ?>
        <?php include_once '../Model/usuarioDao.php';?>
        <div class="row">
             <div class="col-xs-3 col-sm-2"></div>
             <div class="col-xs-12 col-sm-8">
                 <div id="wrapper">
                    <form class="form-horizontal" role="form" method="post" action="../Controller/usersController.php">
        <?php 
            /*$band=0;
            function seleccionar($userSelec){
                $band=1;
                $results_users = usuario($userSelec);
            }*/
        ?>
             <?php 
                if(isset($_SESSION['usuario']))
                    $user = $_SESSION['usuario'];
                echo '<input type="hidden" class="form-control" id="user" name="user" value="'.$user.'">';
                //echo '<input type="hidden" class="form-control" id="accion" name="accion" value="'.$_GET['acc'].'">';
            ?>
        <div class="row">
            <div class="col-md-2"></div>
            <div class="col-xs-12 col-sm-12 col-md-8">
                <div class="table-responsive">
                    <table class="table table-hover table-striped">
                        <tr>
                            <th>User Name</th>
                            <th>First Name</th>
                            <th>Middle Name</th>
                            <th>Last Name</th>
                        <tr>
                        <?php
                            //$band=0;
                            //echo strcmp($_GET['us'],'n');
                            //$u=$_GET['us'];
                            //if($_GET['us']!='n'){//aqui
                            /*if(strcmp($_GET['us'],'n')==0){
                                $band=0;
                            }else{*/
                            if(strcmp($_GET['us'],'n')==0){
                                $band=0;
                            }
                            else{
                                $band=1;
                                $results_users = usuario($_GET['us']);
                            }
                                //$results_users = usuario('profesor');
                                //$results_users = usuario('\''.$_GET['us'].'\'');
                            //$results_users = usuario($u);
                                //echo $results_users[0]['userName'];
                            //}
                            //echo $band;
                            /*function seleccionar($userSelec){
                                $band=1;
                                $results_users = usuario($userSelec);
                                return;
                            }*/
                            $results = usuarios();
                            $cant = count($results);
                            for ($i = 0; $i < $cant; $i++) {
                                echo '<tr class="data" id="' . $results[$i]['userName'] . '">';
                                //echo '<td><a href="#" onclick="seleccionar("'.$results[$i]['userName'].'");">'.$results[$i]['userName'].'</a></td>';
                                //echo '<td><a href="usuarios.php?us=\''.$results[$i]['userName'].'\'">'.$results[$i]['userName'].'</a></td>';
                                //echo '<td><a href="usuarios.php?us='.$results[$i]['userName'].'">'.$results[$i]['userName'].'</a></td>';
                                echo '<td><a href="usuarios.php?us='.$results[$i]['userName'].'">'.$results[$i]['userName'].'</a></td>';
                                echo '<td>'.$results[$i]['firstName'].'</td>';
                                echo '<td>'.$results[$i]['middleName'].'</td>';
                                echo '<td>'.$results[$i]['LastName'].'</td>';
                                echo '</tr>';
                            }
                        ?>
                    </table>
                </div>
            </div>
        </div>
            <br/>
            <!--<div class="row">
             <div class="col-xs-3 col-sm-2"></div>
             <div class="col-xs-12 col-sm-8">
                 <div id="wrapper">
                    <form class="form-horizontal" role="form" method="post" action="../Controller/usersController.php">-->
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><h1><font color="white"><strong>Users</strong></font></h1></label>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <!--<div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Acci&oacute;n</font></label>
                               <select type="text" class="form-control" id="accion" name="accion">
                                   <option value="0">New User</option>
                                   <option value="1">Modify User</option>
                               </select>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>-->
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">User Name</font></label>
                               <?php 
                               //echo $band;
                               //echo $_GET['acc'];
                                if($band==1){
                                    echo '<input type="text" class="form-control" id="userName" name="userName" placeholder="User Name" value="'.$results_users[0]['userName'].'">';
                                    $accion = 1;
                                    echo '<input type="hidden" class="form-control" id="accion" name="accion" value="'.$accion.'">';
                                }else{
                               
                                echo '<input type="text" class="form-control" id="userName" name="userName" placeholder="User Name">';
                                    $accion = 0;
                                    echo '<input type="hidden" class="form-control" id="accion" name="accion" value="'.$accion.'">';
                                 }?>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <?php
                               if($band==0){
                                   ?>
                               <label><font color="white">Password</font></label>
                               <?php 
                               }
                                if($band==1){
                                    echo '<a href="changePassword.php?us='.$results_users[0]['userName'].'">Change Password</a>';
                                    //$pass=encriptar($results_users[0]['passWord']);
                                    echo '<input type="hidden" class="form-control" id="passWord" name="passWord" placeholder="Password" value="">';
                                }else{
                               
                               echo '<input type="text" class="form-control" id="passWord" name="passWord" placeholder="Password">';
                                }?>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">First Name</font></label>
                               <?php 
                                if($band==1){
                                    echo '<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First Name" value="'.$results_users[0]['firstName'].'">';
                                }else{
                               ?>
                               <input type="text" class="form-control" id="firstName" name="firstName" placeholder="First Name">
                               <?php }?>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Middle Name</font></label>
                               <?php 
                                if($band==1){
                                    echo '<input type="text" class="form-control" id="middleName" name="middleName" placeholder="Middle Name" value="'.$results_users[0]['middleName'].'">';
                                }else{
                               ?>
                               <input type="text" class="form-control" id="middleName" name="middleName" placeholder="Middle Name">
                               <?php }?>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Last Name</font></label>
                               <?php 
                                if($band==1){
                                    echo '<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Last Name" value="'.$results_users[0]['LastName'].'">';
                                }else{
                               ?>
                               <input type="text" class="form-control" id="lastName" name="lastName" placeholder="Last Name">
                               <?php }?>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Rol</font></label>
                               <select type="text" class="form-control" id="rol" name="rol">
                                   <?php 
                                        $results = roles();
                                        $cant = count($results);
                                        for ($i = 0; $i < $cant; $i++) {
                                            if($band==1 && $results[$i]['roleCode']==$results_users[0]['roleCode']){
                                                echo '<option value="' . $results[$i]['roleCode'] . '" selected>'.$results[$i]['rolName'].'</option>';
                                            }else{
                                                echo '<option value="' . $results[$i]['roleCode'] . '">'.$results[$i]['rolName'].'</option>';
                                            }
                                        }
                                   ?>
                               </select>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Department</font></label>
                               <select type="text" class="form-control" id="department" name="department">
                                   <?php 
                                        $results = departamentos();
                                        $cant = count($results);
                                        for ($i = 0; $i < $cant; $i++) {
                                            if($band==1 && $results[$i]['idDepartment']==$results_users[0]['idDepartment']){
                                                echo '<option value="' . $results[$i]['idDepartment'] . '" selected>'.$results[$i]['DepartmentName'].'</option>';
                                            }else{
                                                echo '<option value="' . $results[$i]['idDepartment'] . '">'.$results[$i]['DepartmentName'].'</option>';
                                            }  
                                        }
                                   ?>
                               </select>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Company</font></label>
                               <select type="text" class="form-control" id="company" name="company">
                                   <?php 
                                        $results = companias();
                                        $cant = count($results);
                                        for ($i = 0; $i < $cant; $i++) {
                                            if($band==1 && $results[$i]['idCompany']==$results_users[0]['idCompany']){
                                                echo '<option value="' . $results[$i]['idCompany'] . '" selected>'.$results[$i]['companyName'].'</option>';
                                            }else{
                                                echo '<option value="' . $results[$i]['idCompany'] . '">'.$results[$i]['companyName'].'</option>';
                                        
                                            }
                                        }
                                   ?>
                               </select>
                           </div>
                           <div class="col-sm-4"></div>
                        </div>
                        <div class="form-group">
                           <div class="col-sm-4"></div>
                           <div class="col-sm-4">
                               <label><font color="white">Mail</font></label>
                               <?php 
                                if($band==1){
                                    echo '<input type="text" class="form-control" id="mail" name="mail" placeholder="Mail" value="'.$results_users[0]['userMail'].'">';
                                }else{
                               ?>
                               <input type="text" class="form-control" id="mail" name="mail" placeholder="Mail">
                               <?php }?>
                           <div class="col-sm-4"></div>
                           </div>
                        </div>
                        <br/>
                        <div class="col-sm-4"></div>
                        <div class="col-sm-2">
                            <input id="submit" type="image" value="submit" src="../Resources/img/btn_enter.png" alt="Enter" class="enterButton">
                            <!--<button type="button" class="btn btn-success" id="save">
                                Add user
                            </button>
                        </div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-success" id="modify">
                                Modify user
                            </button>-->
                        </div>
                        <div class="col-sm-2">
                            <input id="cancelar" type="image" value="cancelar" src="../Resources/img/btn_cancel.png" alt="Cancel" class="enterButton">
                        </div>
                        <div class="col-sm-4"></div>
                    </form>
                <br/><br/><br/>
                 </div>
             </div>
             <div class="col-xs-3 col-sm-2"></div>
        </div>
        <?php include_once '../PlantillasUI/_footerLayout.php'; ?>
        <?php
              
        ?>
        <script type="text/javascript">
            $('#cancelar').click(function (){
                //$band=0;
                $('#accion').val(0);
                $('#userName').val("");
                $('#passWord').val("");
                $('#firstName').val("");
                $('#middleName').val("");
                $('#lastName').val("");
                $('#rol').selected("1");
                $('#department').selected("1");
                $('#company').selected("1");
                $('#mail').val("");
            });
            /*function encriptar($p){
                var hash = CryptoJS.SHA3($p);
                return hash.toString(CryptoJS.enc.Hex);
            }*/
            $('#submit').click(function(event) {
                event.preventDefault();
                var hash = CryptoJS.SHA3($('#passWord').val());
                $('#passWord').val(hash.toString(CryptoJS.enc.Hex));
                $('.form-horizontal').submit();
            });
            /*$('#submit').click(function(event) {
                $('#passWord').val('Entre');
                if($('#passWord').val()==""){
                    $('#passWord').val('NoLaCambio');
                    $('.form-horizontal').submit();
                }
                else{
                    event.preventDefault();
                    var hash = CryptoJS.SHA3($('#passWord').val());
                    $('#passWord').val(hash.toString(CryptoJS.enc.Hex));
                    $('.form-horizontal').submit();
                }
            });*/
    </script>
    </body>
</html>